1 #include "TempoTools.h"
3 using namespace std::chrono
;
5 TempoTools::TempoTools(RhythmIO
* rhythmio
)
14 long long dummyTime
= (duration_cast
<milliseconds
>(system_clock::now().time_since_epoch())).count();
15 for (int i
= 0; i
< 10; i
++) {
16 oldTime
[i
] = dummyTime
;
17 fileTime
[i
] = dummyTime
;
21 TempoTools::~TempoTools()
25 void TempoTools::createTimeData(std::string levelPath
) {
27 timeKeys
= rio
->createBeatPatterns(levelPath
);
29 void TempoTools::clearTimeData() {
33 rio
->keyPositions
= 0;
35 void TempoTools::proccessDataSlow() {
36 rio
->bufferBeatData(timeKeys
, musicStart
, &hitData
, &cueData
);
38 void TempoTools::setMusicStart(long long mStart
) {
42 void TempoTools::countDown(float* time
, float duration
) {
43 milliseconds ms
= duration_cast
<milliseconds
>(
44 system_clock::now().time_since_epoch());
45 long long expiredTime
= ms
.count();
46 *time
= duration
- (expiredTime
- musicStart
) / 1000.0;
49 double TempoTools::clickTempo(int time
) {
51 clickTimes
.push_back(time
);
52 int size
= clickTimes
.size();
57 else if (size
> limit
) {
58 clickTimes
.erase(clickTimes
.begin());
62 for (int t
= 0; t
< size
- 1; t
++) {
63 combined
+= clickTimes
.at(t
+ 1) - clickTimes
.at(t
);
66 double combinedAv
= combined
/ (size
- 1);
68 double clickRate
= 60000 / combinedAv
;
69 double factor
= clickRate
/ tempo
;
79 short TempoTools::autoPlay(int type
){
80 milliseconds ms
= duration_cast
<milliseconds
>(
81 system_clock::now().time_since_epoch());
82 long long time
= ms
.count();
83 long long difference
= 0;
84 for (int i
= 1; i
< 10; i
++) {
86 difference
= cueFileTime
[i
] - time
;
87 //if(type == 10) std::cout << (difference) << "\n";
88 if (difference
< 16 && difference
> -16 && !autoplayed
[i
]) {
92 else if (difference
< 16 && difference
> -16 && autoplayed
[i
]) {}
94 autoplayed
[i
] = false;
101 short TempoTools::clickAccuracy(int type
, bool cout
) {
102 milliseconds ms
= duration_cast
<milliseconds
>(
103 system_clock::now().time_since_epoch());
105 long long clickTime
= ms
.count();
107 long long difference
;
108 long long oldDifference
;
109 for (int i
= 1; i
< 10; i
++) {
112 difference
= std::abs(fileTime
[i
] - clickTime
);
114 oldDifference
= std::abs(oldTime
[i
] - clickTime
);
118 std::cout
<< "\n ----\t" << (oldDifference
) << " ---- \n"
119 << "\n ----\t" << difference
<< " ---- \n";
122 if (difference
< errorMarginOK
|| oldDifference
< errorMarginOK
) {
123 if (cout
) std::cout
<< "OK\n";
126 else if (difference
> errorMarginOK
){
127 if (cout
) std::cout
<< "Ahead\n";
131 else if (oldDifference
> errorMarginOK
) {
132 if (cout
)std::cout
<< "Behind\n";
138 short TempoTools::clickAccuracyRange(int type
) {
139 milliseconds ms
= duration_cast
<milliseconds
>(
140 system_clock::now().time_since_epoch());
142 long long clickTime
= ms
.count();
144 long long difference
;
145 long long oldDifference
;
146 for (int i
= 1; i
< 10; i
++) {
149 difference
= std::abs(fileTime
[i
] - clickTime
);
151 oldDifference
= std::abs(oldTime
[i
] - clickTime
);
154 std::cout
<< "\n ----\t" << (oldDifference
) << " ---- \n"
155 << "\n ----\t" << difference
<< " ---- \n";
156 //signs are flipped for some reason.
157 if (difference
< errorMarginPerf
|| oldDifference
< errorMarginPerf
) {
161 else if (difference
< errorMarginGood
|| oldDifference
< errorMarginGood
) {
166 else if (difference
< errorMarginOK
|| oldDifference
< errorMarginOK
) {
171 else if (difference
> errorMarginOK
|| oldDifference
> errorMarginOK
) {
179 //when a certain vector's time has expired, switch to the next one and keep the old one in a long long.
180 void TempoTools::moveTicker() {
181 milliseconds ms
= duration_cast
<milliseconds
>(
182 system_clock::now().time_since_epoch());
183 long long ct
= ms
.count();
185 for (int i
= 1; i
< 10; i
++) {
186 if (hitData
.size() != 0) {
187 if (ct
> fileTime
[i
] && hitData
.at(0).at(1) == i
) {
188 oldTime
[i
] = fileTime
[i
];
189 fileTime
[i
] = hitData
.at(0).at(0);
190 hitData
.erase(hitData
.begin());
191 std::cout
<< "\tupdate Hit " << hitData
.size() << "\n";
195 for (int i
= 1; i
< 10; i
++) {
196 if (cueData
.size() != 0) {
197 if (ct
> cueFileTime
[i
] && cueData
.at(0).at(1) == i
* 10) {
198 cueFileTime
[i
] = cueData
.at(0).at(0);
199 cueData
.erase(cueData
.begin());
200 std::cout
<< "\tupdate Cue" << cueData
.size() << "\n";